package com.bitbank.smartdevice.util

import android.content.Context
import android.graphics.BitmapFactory
import cn.sharesdk.framework.Platform
import cn.sharesdk.framework.PlatformActionListener
import cn.sharesdk.framework.ShareSDK
import cn.sharesdk.wechat.friends.Wechat
import com.bitbank.smartdevice.R
import java.util.HashMap

/**
 *  Date：2018/12/18
 *  Author：xulee
 *  Desc：
 */
object ShareUtils {

    /**
     * 分享网页
     */
    fun wechatShare(title: String, text: String, url: String, imageUrl: String) {
        var params = Platform.ShareParams()

        params.shareType = Platform.SHARE_WEBPAGE
        params.title = title
        params.text = text
        params.url = url
        params.imageUrl = imageUrl

        var wechat = ShareSDK.getPlatform(Wechat.NAME)

        wechat.share(params)

        wechat.platformActionListener = object : PlatformActionListener {
            override fun onCancel(p0: Platform?, p1: Int) {

            }

            override fun onComplete(p0: Platform?, p1: Int, p2: HashMap<String, Any>?) {

            }

            override fun onError(p0: Platform?, p1: Int, p2: Throwable?) {

            }
        }
    }

    /**
     * 分享Apk的下载地址
     */
    fun apkDownload(context: Context, title: String, text: String, url: String) {
        var params = Platform.ShareParams()
        var logo = BitmapFactory.decodeResource(context.applicationContext.resources, R.mipmap.ic_launcher)

        params.shareType = Platform.SHARE_WEBPAGE
        params.imageData = logo
        params.title = title
        params.text = text
        params.url = url

        ShareSDK.getPlatform(Wechat.NAME).share(params)
    }
}